package com.qianfeng.openapi.web.master.feign;

import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@FeignClient("OPENAPI-CACHE")
public interface CacheService {

    @RequestMapping(value = "/cache/get/{key}", method = RequestMethod.GET)
    String get(@PathVariable("key") String key);

    @RequestMapping(value = "/cache/setnx/{key}/{value}", method = RequestMethod.POST)
    boolean setnx(@PathVariable("key") String key, @PathVariable("value") String value, @RequestParam("expireSecond") long expireSecond);

    @RequestMapping(value = "/cache/delete/{key}", method = RequestMethod.POST)
    boolean del(@PathVariable("key") String key);

    @RequestMapping(value = "/cache/hmset/{key}", method = RequestMethod.POST)
    boolean hmset(@PathVariable("key") String key, @RequestBody Map<String, Object> map);

    @RequestMapping(value = "/cache/set/{key}/{value}/{expiretime}", method = RequestMethod.POST)
    void set(@PathVariable("key") String key, @PathVariable("value") String value, @PathVariable("expiretime") long expireSecond);

    @RequestMapping(value = "/cache/reverseRangeWithScores", method = RequestMethod.POST)
    List<String> reverseRangeWithScores(@RequestParam("key") String key, @RequestParam("start") int start, @RequestParam("end") int end);


    @PostMapping("/cache/hset/{key}/{field}/{value}")
    void hSet(@PathVariable("key") String key, @PathVariable("field") String field, @PathVariable("value") String value) throws Exception;

    @GetMapping("/cache/hget/{key}/{field}")
    String hGet(@PathVariable("key") String key, @PathVariable("field") String field) throws Exception;

    @PostMapping("/cache/sadd/{key}/{value}")
    Long sAdd(@PathVariable("key") String key,@PathVariable("value")  String value) throws Exception;

    @PostMapping("/cache/sremove/{key}/{value}")
    public Long sRemove(@PathVariable("key") String key,@PathVariable("value")  String value) throws Exception;

    /**
     * 效果和上面的hmset 一样,只不过当我们存放的数据是对象的时候 也是自动转换为json
     * @param key
     * @param data
     * @return
     */
    @RequestMapping(value = "/cache/hmset/{key}", method = RequestMethod.POST)
    boolean hmset(@PathVariable("key") String key, @RequestBody Object data);
}
